package com.demo.yuanzi.util;

import lombok.Data;

    @Data
    public class YuResult<T> {
        private Boolean success;

        private Integer code;

        private String message;

        private T data;

        public static YuResult ok(){
            YuResult result = new YuResult();
            result.setSuccess(true);
            result.setCode(ResultCodeEnum.SUCCESS.getCode());
            result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
            return result;
        }

        public static <T> YuResult ok(T data){
            YuResult result = new YuResult();
            result.setSuccess(true);
            result.setCode(ResultCodeEnum.SUCCESS.getCode());
            result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
            result.setData(data);
            return result;
        }

        public static YuResult fail(){
            YuResult result = new YuResult();
            result.setSuccess(false);
            result.setCode(ResultCodeEnum.FAIL.getCode());
            result.setMessage(ResultCodeEnum.FAIL.getDesc());
            return result;
        }

        public static <T> YuResult fail(T data){
            YuResult result = new YuResult();
            result.setSuccess(false);
            result.setCode(ResultCodeEnum.FAIL.getCode());
            result.setMessage(ResultCodeEnum.FAIL.getDesc());
            result.setData(data);
            return result;
        }


    }
